package cs.asiainfo.config.service.impl;

import cs.asiainfo.config.dao.impl.MemberDaoImpl;
import cs.asiainfo.config.entity.MemberEntity;
import cs.asiainfo.config.service.MemberService;

/**
 * Created by many on 2016/8/10.
 * @author many
 * 会员服务
 */
public class MemberServiceImpl implements MemberService {
    private final static MemberDaoImpl memberDao = new MemberDaoImpl();

    /**
     * 新增会员
     */
    public String createMember(String memberName, String memberAddress, String memberPro) throws Exception{
        String message = "";

        MemberEntity result = memberDao.qryMember(memberName);
        if (result == null){
            MemberEntity memberEntity = new MemberEntity();
            memberEntity.setMemberName(memberName);
            memberEntity.setMemberAddress(memberAddress);
            memberEntity.setMemberPro(memberPro);
            Integer memberId = memberDao.createMember(memberEntity);

            message = "OK. " + memberName + "'s member id is " + memberId;
        }
        else{
            message = "Member name already existed!";
        }
        return message;
    }

    /**
     * 查询会员信息
     */
    public MemberEntity qryMember(String memberName) throws Exception{
        MemberEntity memberEntity = memberDao.qryMember(memberName);
        return memberEntity;
    }
}
